#include<iostream>
#include<cstdio>
#define N 2000001
#define M 20000000
using namespace std;
int read()
{
	char c=0;
	int sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
struct node
{
	int v,nxt;
};
node edge[M+1];
int T,n,lens,s[N+1],head[N+1],rt[N+1],sa[N+1],rk[N+1],len[N+1],slen[N+1];
char c[N+1];
void add(int x,int y)
{
	if (x>y) swap(x,y);
	s[x]++,s[y]--;
	return;
}
void add2(int x,int y)
{
	if (x>y) swap(x,y);
	edge[++lens]=(node){x,head[y]},head[y]=lens;
	return;
}
int main()
{
	freopen("string.in","r",stdin);
	freopen("string.out","w",stdout);
	int ps,d,pv;
	bool op;
	T=read();
	for (int qt=1;qt<=T;++qt)
	{
		n=read(),rk[n+1]=ps=op=lens=0;
		for (int i=1;i<=n;++i) rk[i]=head[i]=s[i]=0;
		for (int i=1;i<=n;++i)
		{
			sa[i]=read()+1;
			if (sa[i]>n)
			{
				op=1;
				break;
			}
			rk[sa[i]]=i;
		}
		if (op)
		{
			puts("-1");
			continue;
		}
		for (int i=1;i<=n;++i)
			if (!rk[i])
			{
				op=1;
				break;
			}
		if (op)
		{
			puts("-1");
			continue;
		}
		for (int i=1;i<=(n<<1)-1;++i) len[i]=read();
		for (int i=1;i<=n;++i)
		{
			if (len[(i<<1)-1]>(min(i,n-i+1)<<1)-1)
			{
				op=1;
				break;
			}
			if (i!=n&&len[i<<1]>(min(i,n-i)<<1))
			{
				op=1;
				break;
			}
		}
		if (op)
		{
			puts("-1");
			continue;
		}
		for (int i=1;i<=n;++i)
		{
			if (ps+slen[ps]-1>=i) slen[i]=min(slen[(ps<<1)-i],ps+slen[ps]-i);
			else slen[i]=0;
			d=(len[(i<<1)-1]-1)>>1;
			if (slen[i]>d||(i+slen[i]<ps+slen[ps]&&slen[i]!=d))
			{
				op=1;
				break;
			}
			while (slen[i]+1<=d) add(rk[i+slen[i]+1],rk[i-slen[i]-1]),slen[i]++;
			if (slen[i]+1<=min(i-1,n-i)) add2(rk[i+slen[i]+1],rk[i-slen[i]-1]);
			if (i+slen[i]>=ps+slen[ps]) ps=i;
		}
		if (op)
		{
			puts("-1");
			continue;
		}
		ps=0;
		for (int i=1;i<=n-1;++i)
		{
			if (ps+slen[ps]-1>=i) slen[i]=min(slen[(ps<<1)-i],ps+slen[ps]-i);
			else slen[i]=0;
			d=len[i<<1]>>1;
			if (slen[i]>d||(i+slen[i]<ps+slen[ps]&&slen[i]!=d))
			{
				op=1;
				break;
			}
			while (slen[i]+1<=d) add(rk[i+slen[i]+1],rk[i-slen[i]]),slen[i]++;
			if (slen[i]+1<=min(i,n-i)) add2(rk[i+slen[i]+1],rk[i-slen[i]]);
			if (i+slen[i]>ps+slen[ps]) ps=i;
		}
		if (op)
		{
			puts("-1");
			continue;
		}
		for (int i=1;i<=n-1;++i)
			if (rk[sa[i]+1]>rk[sa[i+1]+1])
				add2(i,i+1);
		for (int i=1;i<=n;++i) s[i]+=s[i-1];
		for (int i=n;i>=1;--i)
		{
			if (s[i]) rt[i]=rt[i+1];
			else rt[i]=i;
		}
		pv=1,c[0]='a';
		for (int i=1;i<=n;++i)
			if (rt[i]==i)
			{
				c[i]=c[pv-1];
				for (int j=pv;j<=i;++j)
					for (int t=head[j];t>0;t=edge[t].nxt)
						if (!op)
						{
							if (rt[edge[t].v]==rt[i]||c[edge[t].v]=='z')
							{
								op=1;
								break;
							}
							c[i]=max(c[i],(char)(c[edge[t].v]+1));
						}
				for (int j=pv;j<=i;++j) c[j]=c[i];
				pv=i+1;
			}
		if (op)
		{
			puts("-1");
			continue;
		}
		for (int i=1;i<=n;++i) printf("%c",c[rk[i]]);
		puts("");
	}
	return 0;
}
